use std::{cmp::Ordering, io};
use rand::Rng;

fn main() {

    let mut a = 1; // 可修改 
    let b = 2; // 不可修改 final
    // A = a;
    a = a + 1;
    println!("num is {} {}", a, b);
    
    let mut guess_count = 0;
    let r = rand::thread_rng().gen_range(1..=100);
    loop {
        println!("---- 请输入数字(0~100): ----");
        let mut guess = String::new();
        io::stdin().read_line(&mut guess).expect("读取输入出错");
        let guess: u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => continue,
        };
        // let guess: u32 = guess.trim().parse().expect("请输入一个数字!");
        guess_count += 1;
    
        match guess.cmp(&r) {
            Ordering::Less => println!("猜小了"),
            Ordering::Greater => println!("猜大了"),
            Ordering::Equal => {
                println!("猜对了");
                break;
            }
        }
    }

    let mut attr = String::new();
    
    println!("\n====== {}次 猜对 ====== ", guess_count);

}
